
import tree from "@/components/materialQualityPage/testDetectionManage/tree"; //左侧机构树
import TableData from "@/components/stationProductionPage/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
    getUserCompanyTreeList, //左侧机构树接口
    // getGroupTeamPageLists, //主页面列表接口
    // getGroupTeamByFid, //详情
    getLabInfoByCompanyId, //试验室基本信息
    getTesterLists, //检测人员信息
    getTesterInfoByFid, //检测人员信息--详情
    getLabEquipLists, //仪器设备信息
    getLabEquipDetail, //仪器设备信息--详情
} from "@/api/request.js";

export default {
    name: "filing",
    data() {
        return {
            name: "filing", //按钮配置页面代号
            typeData: [
                { text: "试验室基本信息", show: true },
                { text: "检测人员信息", show: false },
                { text: "仪器设备信息", show: false },
            ],
            yj_view: null,
            yj_export: null, //导出
            // construction: formJs.construction, //下拉框施工类型

            // 试验室基本信息
            FromShow: formJs.FromShowLook, //试验室基本信息
            formData: formJs.formData,

            fSourcefileList: [],
            // 试验室基本信息

            // 检测人员信息
            // 分页
            navigatepageNums: null, //是否显示分页
            queryCriteriaData: {},
            fId: null, //当前行数据fId
            row: { fstatus: "" }, //选中行
            table_noe: formJs.table_noe,
            // 分页
            // 检测人员信息

            // 仪器设备信息
            // 分页
            navigatepageNums1: null, //是否显示分页
            queryCriteriaData1: {},
            fId1: null, //当前行数据fId
            row1: { fstatus: "" }, //选中行
            table_tow: formJs.table_tow,

            // 分页
            // 仪器设备信息

            // 列表
            getList: {
                fCompanyid: "", // 左侧选中组织机构id
                fConstructtypeid: "", //查询条件 施工类型id 可不传
                page: 1, //页码
                pageSize: 20, //每页条数
                userId: "", // 查询待办或已办时传 列表页查询不传
                modelType: "", // 0代办 1已办 不传或传空 表示列表页查询
                keyWord: "",
            }, //列表页传参
            loading: false, //列表转载
            tableData: [], //表格列表数据列表
            indexNum: 0, //切换页面获取顺序
            // 列表
            // 详情
            loadingEditDialog: false,
            dialogEditVisible: false,
            dialogTitle: "",
            detailsFrom: formJs.testerForm, //详情展示
            detailsFromData: {}, //详情展示
            //检测人员信息
            testerForm: formJs.testerForm,
            testerFormData: formJs.testerFormData,
            //检测人员信息
            //仪器设备信息
            labEquipForm: formJs.labEquipForm,
            labEquipFormData: formJs.labEquipFormData,
            //仪器设备信息
            // 详情
            // 机构树
            highlightBd: true, //左侧机构树停留背景色
            treelength: false, //左侧树显示隐藏
            checked: true, //查看下级按钮
            showName: "未选择公司",
            companyTree: "", //所有数据
            treeData: [], //左侧树状图数据
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            treeText: {
                companyId: null,
                userId: null,
            },
            checkData: [], //树状图默认选中id
            // 机构树
            userInfo: {}, //登录用户
        };
    },
    components: {
        tree, //左侧组织机构数
        TableData, //主页面列表
        publicForm, //弹框表格
        Pagination, //分页
        elBreadcrumb, //面包屑
    },
    mounted() {
        this.getList.modelType = "2";
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        if (JSON.parse(sessionStorage.getItem("yjSmart-testDetection_treeCheck"))) {
            var id = JSON.parse(
                sessionStorage.getItem("yjSmart-testDetection_treeCheck")
            );
            this.checkData = [id.fCompanyid];
        }

        this.getTree();
        this.btnRole(this.name);
    },
    methods: {
        // 按钮获取
        btnRole(name) {
            var btnList = [];
            var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
            if (ModuleList.length > 0) {
                ModuleList.map((item) => {
                    if (item.fEncode == name) {
                        btnList = item.modulebuttonList;
                    }
                });
                var btnStr = [];
                btnList.map((item) => {
                    btnStr.push(item.fEncode);
                });
                this.yj_view = btnStr.includes("yj_view");
                this.yj_export = btnStr.includes("yj_export");
            } else {
                this.yj_view = true;
                this.yj_export = true;
            }
        },
        // 页签切换
        changeType(e, index) {
            // console.log("页签切换", e, index);
            for (let i in this.typeData) {
                if (parseFloat(i) === index) {
                    this.typeData[i].show = true;
                } else {
                    this.typeData[i].show = false;
                }
            }
            this.indexNum = index;
            this.getList.page = 1;
            this.getList.keyWord = "";
            if (index == 0) {
                this.getLabInfoForm(this.getList);
            } else if (index == 1) {
                this.getTesterForm(this.getList);
            } else if (index == 2) {
                this.getLabEquipForm(this.getList);
            }
            // this.typeDataNum = index;
        },
        // 左侧树结构
        getTree() {
            this.treeText = {
                companyId: this.userInfo.companyId,
                userId: this.userInfo.userId,
                // text: "4", // 0其他  1 砼拌合站 2水稳 3沥青
            };
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        var companyTree = res.data.userCompanyTreeList;
                        this.treeData = this.commonJs.tranListToTreeData(companyTree);

                        if (this.treeData[0].children == undefined) {
                            this.treelength = false; //左侧组织机构是否显示
                        } else {
                            this.treelength = true;
                        }

                        if (this.checkData[0]) {
                            this.showName = JSON.parse(
                                sessionStorage.getItem("yjSmart-testDetection_treeCheck")
                            ).fShortname;
                            this.getList.fCompanyid = this.checkData[0];
                        } else {
                            this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
                            this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
                            this.checkData[0] = this.treeData[0].fCompanyid;
                        }

                        this.typeData.map((item, index) => {
                            if (index == 0) {
                                item.show = true;
                            } else {
                                item.show = false;
                            }
                        });
                        this.getLabInfoForm(this.getList);
                        // this.getTesterForm(this.getList);
                        // this.getLabEquipForm(this.getList);
                        // 列表
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },

        // 点击左侧机构树
        handleNodeClick(data) {
            this.showName = data.fShortname; //顶部显示机构名
            this.getList = {
                fCompanyid: data.fCompanyid, // 左侧选中组织机构id
                fConstructtypeid: "", //查询条件 施工类型id 可不传
                page: 1, //页码
                pageSize: 20, //每页条数
                userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
                modelType: 2, // 0代办 1已办 不传或传空 表示列表页查询
                keyWord: "",
            };
            if (this.indexNum == 0) {
                this.getLabInfoForm(this.getList);
            } else if (this.indexNum == 1) {
                this.getTesterForm(this.getList);
            } else if (this.indexNum == 2) {
                this.getLabEquipForm(this.getList);
            }
        },
        // 查询按钮
        getTableList(num){
            this.getList.page=1;
            if (num==1) {
                this.getTesterForm(this.getList);
            }else{
                this.getLabEquipForm(this.getList);
            }
        },
        // 获取数据
        //试验室基本信息
        getLabInfoForm(data) {
            this.loading = true;
            getLabInfoByCompanyId({
                companyId: data.fCompanyid,
            })
                .then((res) => {
                    if (res.errcode == 0) {

                        if (res.data.labbasicinfo == null) {
                            this.formData = {
                                fId: "", // 信息fId
                                fCompanyid: "", // 所属标段ID
                                fCompanyname: "", // 所属标段名称
                                fJlid: "", // 所属监理ID
                                fJlname: "", // 所属监理名称
                                fProjectid: "", // 所属项目ID
                                fProjectname: "", // 所属项目名称
                                fLabname: "", // 实验室名称
                                fLabshortname: "", // 实验室简称
                                fAuthorizedagencyid: "", // 授权机构ID
                                fAuthorizedagencyname: "", // 授权机构名称
                                fAuthorizedagencycertificatetype: "", // 授权机构登记证书
                                fAuthorizedagencycertificateno: "", // 授权机构证书编号
                                fBuilddates: "", // 实验室设立日期
                                fEngineercount: "", // 试验检测工程师人数（人）
                                fTestercount: "", // 试验检测员人数（人）
                                fBuildingarea: "", // 试验检测用房总面积
                                fAuthorizedsuperintendentid: "", // 授权负责人ID
                                fAuthorizedsuperintendentname: "", // 授权负责人名称
                                fAuthorizedsuperintendentcertificateno: "", // 授权负责人持证书号
                                fAuthorizedsuperintendenttitle: "", // 授权负责人职称
                                fAuthorizedsuperintendenttel: "", // 授权负责人联系电话
                                fLabaddress: "", // 工地实验室地址
                                fPostalcode: "", // 邮编
                                fLabtel: "", // 办公联系电话
                                fFile: "", // 附件资料ID
                                fAuthorizedscope: "", // 授权业务范围
                                fileList: [],
                            };
                        } else {
                            this.formData = res.data.labbasicinfo;
                        }
                        this.fSourcefileList = this.formData.fileList;
                        this.loading = false;
                    } else {
                        this.$message.error("试验室基本信息", res.msg);
                        this.loading = false;
                    }
                })
                .catch(() => {
                    this.loading = false;
                });
        },
        //检测人员信息
        getTesterForm(data) {
            this.loading = true;
            getTesterLists({
                companyId: data.fCompanyid, // 左侧选中组织机构id
                page: data.page, // 当前页码
                pageSize: 20, // 每页显示条数
                keyWord: data.keyWord
            })
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.tableData = res.data.testerList.list;
                        that.queryCriteriaData = res.data.testerList;
                        that.navigatepageNums =
                            that.queryCriteriaData.navigatepageNums.length;
                    } else {
                        this.$message.error("检测人员信息", res.msg);
                        this.loading = false;
                    }
                })
                .catch(() => {
                    this.loading = false;
                });
        },
        //仪器设备信息
        getLabEquipForm(data) {
            this.loading = true;
            getLabEquipLists({
                companyId: data.fCompanyid, // 左侧选中组织机构id
                page: data.page, // 当前页码
                pageSize: 20, // 每页显示条数
                keyWord: data.keyWord
            })
                .then((res) => {
                    if (res.errcode == 0) {
                        var that = this;
                        that.loading = false;
                        that.tableData = res.data.labEquipLists.list;
                        that.queryCriteriaData1 = res.data.labEquipLists;
                        that.navigatepageNums1 =
                            that.queryCriteriaData1.navigatepageNums.length;
                    } else {
                        this.$message.error("仪器设备信息", res.msg);
                        this.loading = false;
                    }
                })
                .catch(() => {
                    this.loading = false;
                });
        },
        // 获取数据

        // 刷新
        Refresh(data) {
            if (this.indexNum == 1) {
                this.getTesterForm(data);
            } else if (this.indexNum == 2) {
                this.getLabEquipForm(data);
            }
        },

        // 点击当前
        rowChange(val) {
            this.row = val;
            this.fId = val.fId;
        },
        rowChange1(val) {
            this.row1 = val;
            this.fId1 = val.fId;
        },
        // 点击查看
        yj_viewForm(row, label) {
            this.row = row;
            this.fId = row.fId;
            if (label == "姓名") {
                this.dialogTitle = "检测人员信息---查看";
                this.detailsFrom = this.testerForm;
                this.detailsFromData = this.testerFormData;
                this.editText(this.fId, 0);
            }
        },
        yj_viewForm1(row, label) {
            this.row1 = row;
            this.fId1 = row.fId;
            if (label == "设备编号") {
                this.dialogTitle = "仪器设备信息---查看";
                this.detailsFrom = this.labEquipForm;
                this.detailsFromData = this.labEquipFormData;
                this.editText(this.fId1, 1);
            }
        },
        // 查看
        editText(id, num) {
            if (id != "" && id != null) {
                this.loadingEditDialog = true; //弹框loading
                if (num == 0) {
                    getTesterInfoByFid({
                        fId: id,
                    })
                        .then((res) => {
                            if (res.errcode == 0) {
                                this.dialogEditVisible = true;
                                this.loadingEditDialog = false;
                                this.detailsFromData = res.data.tester;
                            } else {
                                this.$message.error("检测人员信息---详情", res.msg);
                                this.loadingEditDialog = false;
                            }
                        })
                        .catch(() => {
                            console.log("检测人员信息---详情接口报错");
                            this.loadingEditDialog = false;
                        });
                } else if (num == 1) {
                    getLabEquipDetail({
                        fId: id,
                    })
                        .then((res) => {
                            if (res.errcode == 0) {
                                this.loadingEditDialog = false;
                                this.dialogEditVisible = true;
                                this.detailsFromData = res.data.equipment;
                            } else {
                                this.$message.error("仪器设备信息---详情", res.msg);
                                this.loadingEditDialog = false;
                            }
                        })
                        .catch(() => {
                            console.log("仪器设备信息---详情接口报错");
                            this.loadingEditDialog = false;
                        });
                }
            } else {
                return this.$message.error("请先选择需要查看的数据");
            }
        },

        getDate() { },
        // 获取页面容器高度
        getHeight() {
            // var h = document.documentElement.clientHeight; //获取页面可见高度
        },

        selectionChange() { },
        // 排序方法
        sortChange() { },
    },
};

